{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "\"\"\"\n",
    "初步学习装饰器\n",
    "函数名称打印\n",
    "\"\"\"\n",
    "def print_function_name(func):\n",
    "    def inner():\n",
    "        print(\"函数名称：\", func.__name__)\n",
    "        func()\n",
    "        print(\"运行结束\")\n",
    "    return inner\n",
    "\n",
    "@print_function_name\n",
    "def func1():\n",
    "    print(\"函数1运行\")\n",
    "\n",
    "@print_function_name    \n",
    "def func2():\n",
    "    print(\"函数2运行\")\n",
    "    \n",
    "func1()\n",
    "func2()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-30T01:18:00.572284Z",
     "start_time": "2024-10-30T01:18:00.569422Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def person():\n",
    "    money = 0\n",
    "    def work():\n",
    "        nonlocal money\n",
    "        money += 1\n",
    "        return money\n",
    "    return work\n",
    "\n",
    "res = person()\n",
    "print(res())\n",
    "print(res())"
   ],
   "id": "ee7657f804bea86b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n"
     ]
    }
   ],
   "execution_count": 4
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
